<template>
    <div>
        <el-form ref="agelRef" :model="form1" label-width="150px" style="padding:0 40px 0px 20px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="任务名称" prop="taskName">
                        {{ form1.taskName }}
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="最新维护人" prop="maintainer">
                        {{ form1.maintainer }}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="最新维护时间" prop="maintainTime">
                        {{ form1.maintainTime }}
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="行政区划分析级别" prop="isCity" @change="changeCity">
                        <el-radio-group v-model="form1.isCity">
                            <el-radio label="0">按区县</el-radio>
                            <el-radio label="1">按地市</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <template v-if="form1.isCity == '0'">
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane v-for="(item, index) in form1.areaList" :key="index"
                        :label="item.province == item.city ? item.province + item.area : item.province + item.city + item.area"
                        :name="index">
                        <el-form-item label="建筑物" :prop="`areaList.` + index + '.building'" :rules="rules.building">
                            <el-input v-model="item.building" placeholder="请输入建筑物" type="textarea" :rows="5"
                                maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="地震灾害重点隐患" :prop="`areaList.` + index + '.disasterHiddenDanger'"
                            :rules="rules.disasterHiddenDanger">
                            <el-input v-model="item.disasterHiddenDanger" placeholder="请输入地震灾害重点隐患" type="textarea"
                                :rows="5" maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="生命线系统" :prop="`areaList.` + index + '.lifelineSystem'"
                            :rules="rules.lifelineSystem">
                            <el-input v-model="item.lifelineSystem" placeholder="请输入生命线系统" type="textarea" :rows="5"
                                maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="重大基础设施" :prop="`areaList.` + index + '.majorInfrastructure'"
                            :rules="rules.majorInfrastructure">
                            <el-input v-model="item.majorInfrastructure" placeholder="请输入重大基础设施" type="textarea" :rows="5"
                                maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="其他年度风险应对策略">
                            <el-input v-model="item.otherAnnualDisaster" placeholder="请输入其他年度风险应对策略" type="textarea"
                                :rows="5" maxlength="2000" show-word-limit />
                        </el-form-item>
                    </el-tab-pane>
                </el-tabs>
            </template>
            <template v-else>
                <el-tabs v-model="activeName" type="card">
                    <el-tab-pane v-for="(item, index) in form1.areaList" :key="index"
                        :label="item.province == item.city ? item.city : item.province + item.city" :name="index">
                        <el-form-item label="建筑物" :prop="`areaList.` + index + '.building'" :rules="rules.building">
                            <el-input v-model="item.building" placeholder="请输入建筑物" type="textarea" :rows="5"
                                maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="地震灾害重点隐患" :prop="`areaList.` + index + '.disasterHiddenDanger'"
                            :rules="rules.disasterHiddenDanger">
                            <el-input v-model="item.disasterHiddenDanger" placeholder="请输入地震灾害重点隐患" type="textarea"
                                :rows="5" maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="生命线系统" :prop="`areaList.` + index + '.lifelineSystem'"
                            :rules="rules.lifelineSystem">
                            <el-input v-model="item.lifelineSystem" placeholder="请输入生命线系统" type="textarea" :rows="5"
                                maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="重大基础设施" :prop="`areaList.` + index + '.majorInfrastructure'"
                            :rules="rules.majorInfrastructure">
                            <el-input v-model="item.majorInfrastructure" placeholder="请输入重大基础设施" type="textarea" :rows="5"
                                maxlength="2000" show-word-limit />
                        </el-form-item>
                        <el-form-item label="其他年度风险应对策略" :prop="`areaList.` + index + '.otherAnnualDisaster'"
                            :rules="rules.otherAnnualDisaster">
                            <el-input v-model="item.otherAnnualDisaster" placeholder="请输入其他年度风险应对策略" type="textarea"
                                :rows="5" maxlength="2000" show-word-limit />
                        </el-form-item>
                    </el-tab-pane>
                </el-tabs>
            </template>
        </el-form>
    </div>
</template>

<script setup>
import { getArea } from "@/api/suggestions/analyse.js";
const { proxy } = getCurrentInstance();
const emit = defineEmits();
const props = defineProps({
    form1: {
        default: {},
        type: Object,
    },
});
const activeName = ref(0)
const data = reactive({
    rules: {
        building: [{ required: true, message: "请输入建筑物", trigger: 'blur', }],
        disasterHiddenDanger: [{ required: true, message: "请输入地震灾害重点隐患", trigger: 'blur' }],
        lifelineSystem: [{ required: true, message: '请输入生命线系统', trigger: 'blur' }],
        majorInfrastructure: [{ required: true, message: '请输入重大基础设施', trigger: 'blur' }],
    }
})
const { rules } = toRefs(data)
const { form1 } = toRefs(props)

// 初始下标
function initActiveName() {
    activeName.value = 0;
}


function changeCity() {
    activeName.value = 0;
    getAreaData({ flag: form1.value.isCity, taskDistrict: form1.value.taskDistrict, suggestionName: '年度风险应对策略建议', taskNum: form1.value.taskNum })
}

// 获取 区县或者地市
function getAreaData(isCity) {
    getArea(isCity).then(response => {
        emit("changeAreaList1", response.data['年度风险应对策略建议']);
    })
}

function getAreaList1() {
    emit("getAreaList1", form1.value.areaList);
}

defineExpose({
    getAreaList1,
    initActiveName
})
</script>